<template>
  <view class="container">
    <!-- 收藏列表 -->
    <view class="favorite-list">
      <view v-if="favoriteList.length === 0" class="empty-state">
        <image src="/static/empty-favorite.png" mode="aspectFit" class="empty-image"></image>
        <text class="empty-text">暂无收藏商品</text>
      </view>

      <view v-else class="product-grid">
        <view v-for="item in favoriteList" :key="item.id" class="product-item">
          <view class="product-card">
            <image :src="item.image" mode="aspectFill" class="product-image" @click="goToDetail(item.id)"></image>
            <view class="product-info">
              <text class="product-name">{{ item.name }}</text>
              <view class="product-price-row">
                <text class="product-price">¥{{ item.price }}</text>
                <text class="product-original-price" v-if="item.originalPrice">¥{{ item.originalPrice }}</text>
              </view>
              <view class="product-actions">
                <button class="add-cart-btn" @click="addToCart(item)">加入购物车</button>
                <button class="remove-favorite-btn" @click="removeFavorite(item)">取消收藏</button>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';

// 模拟收藏商品数据
const favoriteList = ref([
  {
    id: 1,
    name: '冰红茶',
    price: 3.5,
    originalPrice: 4.0,
    image: '/static/Advertisement/binghongcha.jpeg',
    description: '清爽解渴，夏日必备'
  },
  {
    id: 2,
    name: '脉动',
    price: 4.0,
    originalPrice: 5.0,
    image: '/static/Advertisement/maidong.jpeg',
    description: '补充能量，活力满满'
  },
  {
    id: 3,
    name: '芬达',
    price: 3.0,
    originalPrice: 3.5,
    image: '/static/Advertisement/fenda.jpeg',
    description: '橙味汽水，清爽怡人'
  }
]);

// 跳转到商品详情
const goToDetail = (productId: number) => {
  uni.navigateTo({
    url: `/pages/product/detail?id=${productId}`
  });
};

// 加入购物车
const addToCart = (item: any) => {
  uni.showToast({
    title: '已加入购物车',
    icon: 'success'
  });
};

// 取消收藏
const removeFavorite = (item: any) => {
  uni.showModal({
    title: '提示',
    content: '确定取消收藏该商品吗？',
    success: (res) => {
      if (res.confirm) {
        // 模拟删除操作
        const index = favoriteList.value.findIndex(i => i.id === item.id);
        if (index > -1) {
          favoriteList.value.splice(index, 1);
          uni.showToast({
            title: '已取消收藏',
            icon: 'success'
          });
        }
      }
    }
  });
};

// 页面加载时获取收藏列表
onMounted(() => {
  // TODO: 调用获取收藏列表接口
});
</script>

<style>
.container {
  min-height: 100vh;
  background-color: #f5f5f5;
  padding: 10px;
}

.favorite-list {
  padding: 10px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 0;
}

.empty-image {
  width: 120px;
  height: 120px;
  margin-bottom: 10px;
}

.empty-text {
  color: #999;
  font-size: 14px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.product-item {
  background-color: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.product-card {
  display: flex;
  flex-direction: column;
}

.product-image {
  width: 100%;
  height: 150px;
  object-fit: cover;
}

.product-info {
  padding: 10px;
}

.product-name {
  font-size: 14px;
  color: #333;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.product-price-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.product-price {
  font-size: 16px;
  color: #ff6b6b;
  font-weight: bold;
}

.product-original-price {
  font-size: 12px;
  color: #999;
  text-decoration: line-through;
}

.product-actions {
  display: flex;
  gap: 8px;
}

.add-cart-btn,
.remove-favorite-btn {
  flex: 1;
  font-size: 12px;
  padding: 4px 0;
  border-radius: 15px;
  border: none;
}

.add-cart-btn {
  background-color: #ff6b6b;
  color: #ffffff;
}

.remove-favorite-btn {
  background-color: #f0f0f0;
  color: #666;
}
</style> 